package get_test

import (
	"fmt"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"

	"github.com/werf/werf/v2/test/pkg/utils"
)

var _ = Describe("helm get-something", func() {
	envName := "test"

	BeforeEach(func(ctx SpecContext) {
		SuiteData.CommitProjectWorktree(ctx, SuiteData.ProjectName, utils.FixturePath("base"), "initial commit")
		SuiteData.Stubs.SetEnv("WERF_ENV", envName)
	})

	It("should receive release name (default scheme)", func(ctx SpecContext) {
		output := utils.SucceedCommandOutputString(
			ctx,
			SuiteData.GetProjectWorktree(SuiteData.ProjectName),
			SuiteData.WerfBinPath,
			"helm", "get-release",
		)

		Expect(output).Should(ContainSubstring(utils.ProjectName() + "-" + envName))
	})

	It("should receive namespace name (default scheme)", func(ctx SpecContext) {
		output := utils.SucceedCommandOutputString(
			ctx,
			SuiteData.GetProjectWorktree(SuiteData.ProjectName),
			SuiteData.WerfBinPath,
			"helm", "get-namespace",
		)

		Expect(output).Should(ContainSubstring(utils.ProjectName() + "-" + envName))
	})

	It("should receive namespace name (default scheme)", func(ctx SpecContext) {
		output := utils.SucceedCommandOutputString(
			ctx,
			SuiteData.GetProjectWorktree(SuiteData.ProjectName),
			SuiteData.WerfBinPath,
			"helm", "get-namespace",
		)

		Expect(output).Should(ContainSubstring(utils.ProjectName() + "-" + envName))
	})

	It("should receive autogenerated values", func(ctx SpecContext) {
		output := utils.SucceedCommandOutputString(ctx, SuiteData.GetProjectWorktree(SuiteData.ProjectName), SuiteData.WerfBinPath, "helm", "get-autogenerated-values", "--stub-tags")

		for _, substrFormat := range []string{
			"env: %[2]s",
			"namespace: %[1]s-%[2]s",
			"name: %[1]s",
		} {
			Expect(output).Should(ContainSubstring(fmt.Sprintf(substrFormat, utils.ProjectName(), envName)))
		}
	})
})
